package org.xurui.bsj.protocol.provider;

import lombok.extern.slf4j.Slf4j;
import org.xurui.bsj.protocol.command.CmdCodec;
import org.xurui.bsj.protocol.command.impl.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class CmdCodecProvider {

    List<CmdCodec> cmdCodecs = null;

    private static CmdCodecProvider singObj = null;

    private CmdCodecProvider() {
        super();
        initCodec();
    }

    public static CmdCodecProvider getInstance() {
        if (null == singObj ) {
            synchronized(CmdCodecProvider.class){
                if(singObj == null){
                    singObj = new CmdCodecProvider();
                }
            }
        }
        return singObj;
    }

    /**
     *
     * @param cmd 命令CMD
     * @return
     */
    public CmdCodec getCmdCodecByCmd(String cmd){
        for(int i=0;i<cmdCodecs.size();i++){
            if(cmdCodecs.get(i).supportsCmd(cmd)){
                return cmdCodecs.get(i);
            }
        }
        return null;
    }

    //反射加载解码
    private void initCodec(){
        cmdCodecs = new ArrayList<>();
        cmdCodecs.add(new CmdCodec_DEVICE_LOGIN());
        cmdCodecs.add(new CmdCodec_ALARM_POWER());
        cmdCodecs.add(new CmdCodec_REPORT_CROSS_BORDER());
        cmdCodecs.add(new CmdCodec_REPORT_LOCATION_INFO());
        cmdCodecs.add(new CmdCodec_REPORT_HEARTBEAT());
        cmdCodecs.add(new CmdCodec_REPORT_CALL_LOG());
        cmdCodecs.add(new CmdCodec_REPORT_SOS());
        cmdCodecs.add(new CmdCodec_DEVICE_STATUS());
        cmdCodecs.add(new CmdCodec_REPORT_SMS_READ());
        cmdCodecs.add(new CmdCodec_REPORT_HEALTH());
        cmdCodecs.add(new CmdCodec_REPORT_DEVICE_INFO());
        cmdCodecs.add(new CmdCodec_GET_WEATHER_INFO());
        cmdCodecs.add(new CmdCodec_SET_INCOMING_CALL());
        cmdCodecs.add(new CmdCodec_SET_NORMAL_BUTTON());
        cmdCodecs.add(new CmdCodec_SET_SERVER_INFO());
        cmdCodecs.add(new CmdCodec_LOCATION_INFO_GET());
        cmdCodecs.add(new CmdCodec_FREQUENCY_LOCATION_SET());
        cmdCodecs.add(new CmdCodec_REMOTE_OPERATE_TERMINAL());
        cmdCodecs.add(new CmdCodec_SET_REGIONAL_ALARM());
        cmdCodecs.add(new CmdCodec_SET_HEARTBEAT());
        cmdCodecs.add(new CmdCodec_SET_MODEL());
        cmdCodecs.add(new CmdCodec_REQUEST_CALL());
        cmdCodecs.add(new CmdCodec_SET_CLASS_MODEL());
        cmdCodecs.add(new CmdCodec_SEND_SMS());
        cmdCodecs.add(new CmdCodec_SET_LOCATION_MODE());
        cmdCodecs.add(new CmdCodec_SET_REDAY_MODE());
        cmdCodecs.add(new CmdCodec_SET_CLOCK());
        cmdCodecs.add(new CmdCodec_SET_CALL_DURATION());
        cmdCodecs.add(new CmdCodec_SET_HEALTH());
        cmdCodecs.add(new CmdCodec_SET_DEVICE_INFO());
        cmdCodecs.add(new CmdCodec_SET_DEVICE_RFID());
        cmdCodecs.add(new CmdCodec_SET_LOCAL_NUMBER());
        cmdCodecs.add(new CmdCodec_SET_IDCARD_NUMBER());
        cmdCodecs.add(new CmdCodec_GET_NORMAL_BUTTON());
        cmdCodecs.add(new CmdCodec_GET_CLASS_MODEL());
        cmdCodecs.add(new CmdCodec_GET_INCOMING_CALL());
        cmdCodecs.add(new CmdCodec_GET_SMS_PORT());
        cmdCodecs.add(new CmdCodec_GET_SERVICE_MSG());
        cmdCodecs.add(new CmdCodec_GET_IDCARD_NUMBER());
        cmdCodecs.add(new CmdCodec_GET_HEALTH_INFO());
        cmdCodecs.add(new CmdCodec_GET_TRIP_INFO());
        cmdCodecs.add(new CmdCodec_GET_STUDENT_HEALTH());
        cmdCodecs.add(new CmdCodec_GET_STUDENT_IDENTITY());
        cmdCodecs.add(new CmdCodec_SET_VOLUME());
        cmdCodecs.add(new CmdCodec_SET_SHUTDOWN());
        //TODO 所有编解码器都要手动添加

    }



}
